<?php

$uid = $_SESSION['tcADMINID'];

$spl_char = array(" ", "&", "|", "~", "!", "@", "#", "$", "%", "^", "*", "(", ")", "+", "=", "{", "}", ":", ";","'",'"',"<",">","?","/",",","\\","-");

if(isset($_POST['save_approval']))
{
			$item = $_POST['item'];
			$desc = $_POST['desc'];
			$cat = $_POST['category'];
			$sub_cat = $_POST['sub_category'];
			$contactemail = $_POST['contactemail'];
			$showcontactemail = $_POST['showcontactemail'];
			$address1 = $_POST['address1'];
			$address2 = $_POST['address2'];
			$city = $_POST['city'];
			$state = $_POST['state'];
			$postcode = $_POST['postcode'];
			$phone = $_POST['phone'];
			$fax = $_POST['fax'];
			$businessdesc = mysql_real_escape_string($_POST['maincont']);
			$listinglevel = $_POST['listinglevel'];
			
			if($listinglevel == 1)
			{
				$amount = 10;
				$duration = 28;
			}
			else
			{
				$amount = 15;
				$duration = 28;
			}
			$path = "../uploads/adimages/";
			$thumb_path = "../uploads/adimages/thumb/";
			$imageformaterror = 0;
			
			for($i=1;$i<=count($_FILES);$i++) {

				if($_FILES['tempimage'.$i]['name'] != "" and ($_FILES['tempimage'.$i]['type'] == "image/gif" || $_FILES['tempimage'.$i]['type'] == "image/pjpeg" || $_FILES['tempimage'.$i]['type'] == "image/jpeg") || ($_FILES['tempimage'.$i]['type'] == "image/png")) {

					$temp_name = str_replace($spl_char, "", $_FILES['tempimage'.$i]['name']);
					$temp_name =  preg_replace("([.]+)",".",$temp_name);
					
					$photos_pic_stored_name = mktime(date("H"), date("i"), date("s"), date("n"), date("j"), date("Y"))."_".$temp_name;
					move_uploaded_file($_FILES['tempimage'.$i]['tmp_name'], $path.$photos_pic_stored_name);
					
					$stored_image_text .= "'".$photos_pic_stored_name."',";

				}
				else {
					$stored_image_text .= "'',";
				}
			}
			

			if($imageformaterror == 0)
			{
				$cust = time();
				
				mysql_query("insert into classifieds_ads (Item, Description, Category, sub_category, ListingLevel, TempImage1, TempImage2, TempImage3, TempImage4, TempImage5, TempImage6, ContactEmail, ShowEmail, Address1, Address2, City, State, Postcode, Phone, Fax, BusinessDesc, InsertedBy, InsertedDate,TransactionId,TotalAmount, Duration, Cust, Status) values('$item', '$desc', '$cat','$sub_cat', '$listinglevel', ".$stored_image_text."'$contactemail', '$showcontactemail', '$address1', '$address2', '$city', '$state', '$postcode', '$phone', '$fax', '$businessdesc', '$uid', now(),'submitted by admin', '$amount', '$duration', '$cust', 1)");
				
				$lastinsertid = mysql_insert_id();
				
				
				$e = mysql_fetch_array(mysql_query("select * from users where Id='$uid'"));
						$email = "ida@ecstasoft.com";;
						$from = "From: <$email>";
							$to = $TC_Email;
							$subject = "New Ad is submitted in Study sage";
							$message = "
			Hello,
			
			A new Ad is submitted in Study sage.
			
			Submited By:".$e['FirstName']." ".$e['LastName']."
			
			Please login using the below link to approve it.
			
			".$pathu_admin."
			
			";
						
							mail($to, $subject, $message, $from);
							
							//header("location:index.php?tc=ads_add&_s=T&_s=1");
							echo "<script>window.location='index.php?tc=classifieds_ads&_s=T&_s=1'</script>";
		
							
				//to paypal
				
				
			}
			else
			{
				//header("location:index.php?tc=ads_add&_s=T&_e=1");
				echo "<script>window.location='index.php?tc=classifieds_ads&_s=T&_e=1'</script>";
			}
}
?>